<template>
  <div>
    <headerNav title="我的关注"></headerNav>
    <div class="list">
      <div class="item" v-for="item in list" :key="item.id">
        <img v-if="item.head_img" :src="$axios.defaults.baseURL+item.head_img" alt class="pt" />
        <img v-else src="../assets/01.jpg" alt class="pt" />
        <div class="info">
          <div class="name">{{item.nickname}}</div>
          <div class="date">{{item.create_date.split("T")[0]}}</div>
        </div>
        <div class="cancelbtn" @click="cancelAttention(item.id)">取消关注</div>
      </div>
    </div>
  </div>
</template>

<script>
import headerNav from "../components/headerNav";
export default {
  data() {
    return {
      list: [],
    };
  },
  components: {
    headerNav,
  },
  // 静态页面写完,数据渲染刷新
  created() {
    this.loadPage();
  },
  methods: {
    loadPage() {
      this.$axios({
        url: "/user_follows",
      }).then((res) => {
        console.log(res.data); // 将数据存放放在 data 做渲染
        this.list = res.data.data;
      });
    },
    cancelAttention(id) {
      this.$axios({
        method: "get",
        url: "user_unfollow/" + id,
      }).then((res) => {
        console.log(res.data); // 取消关注
        this.loadPage();
      });
    },
  },
};
</script>

<style lang="less" scoped>
.list {
  .item {
    display: flex;
    align-items: center;
    padding: 20/360 * 100vw;
    border-bottom: 1px solid #e4e4e4;
  }
  .pt {
    width: 40/360 * 100vw;
    height: 40/360 * 100vw;
    object-fit: cover;
    border-radius: 50%;
  }
  .info {
    flex: 1;
    padding-left: 16/360 * 100vw;
  }
  .name {
    font-size: 16/360 * 100vw;
  }
  .date {
    font-size: 14/360 * 100vw;
    color: #888;
  }
  .cancelbtn {
    background: #e4e4e4;
    font-size: 16/360 * 100vw;
    line-height: 30/360 * 100vw;
    padding: 0 15/360 * 100vw;
    border-radius: 15/360 * 100vw;
  }
}
</style>